package com.ljfiction.book.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ljfiction.book.R;
import com.ljfiction.book.activitys.BookDetailsActivity;
import com.ljfiction.book.activitys.Reading2Activity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/8/17.
 */

public class GeiveMunoyAdapter extends BaseAdapter {
    private Context context;
    private int[] dataimage = {R.mipmap.xiaolajiaoone, R.mipmap.xiaolajiaotow, R.mipmap.xiaolajiaothree, R.mipmap.xiaolajiaofour, R.mipmap.xiaolajiaofive, R.mipmap.xiaolajiaosex};
    private String[] dataString = {"188辣椒", "288辣椒", "588辣椒", "888辣椒", "1888辣椒", "8888"};
    private int type = 1;

    public GeiveMunoyAdapter(Context context, int type) {
        this.context = context;
        this.type = type;
    }

    @Override
    public int getCount() {
        return dataimage.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.geivemoney_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (type == 1) {
            if (position == BookDetailsActivity.isgridviewselect) {
                viewHolder.frameLayout.setBackgroundResource(R.drawable.shape_giverewardok);
            } else {
                viewHolder.frameLayout.setBackgroundResource(R.drawable.shape_givereward);
            }
        } else {
            if (position == Reading2Activity.isgridviewselect) {
                viewHolder.frameLayout.setBackgroundResource(R.drawable.shape_giverewardok);
            } else {
                viewHolder.frameLayout.setBackgroundResource(R.drawable.shape_givereward);
            }
        }

        viewHolder.imageGivemoneyitem.setImageResource(dataimage[position]);
        if (position == dataString.length - 1) {
            viewHolder.songyijianjiao.setVisibility(View.VISIBLE);
        }else {
            viewHolder.songyijianjiao.setVisibility(View.GONE);
        }
        viewHolder.textGivemoneyitem.setText(dataString[position]);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.image_givemoneyitem)
        ImageView imageGivemoneyitem;
        @BindView(R.id.text_givemoneyitem)
        TextView textGivemoneyitem;
        @BindView(R.id.backgroud_giveitem)
        FrameLayout frameLayout;
        @BindView(R.id.songyilajiao)
        TextView songyijianjiao;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
